import React, { Component } from 'react';
import {
	StyleSheet, Text, View, TouchableOpacity, Image
} from "react-native";
import { GLOBAL } from '../../../config/global';
import { style } from '../../../theme/style';
import Utils from '../../../utils/utils';
import MethodUtil from '../../../utils/MethodUtil';

const scale = GLOBAL.SCALE;


export class DorenCard extends Component {
	constructor(props) {
		super(props);
		this.state = {

		}
	}

	//单选
	_single = (itemData) => {
		let { callBack } = this.props;
		itemData.checked = !itemData.checked;
		callBack && callBack(itemData);
	}


	render() {
		let { itemData, salesType, applyId } = this.props;
		let item = itemData || {};
		const correct = require('../../../imgs/global/correct.png');
		let isEidt = item.hasOwnProperty("checked");
		return (
			<View style={styles.offerItem}>
				<TouchableOpacity onPress={() => { if (!isEidt || (item.canOperateData === "N")) { return false; } this._single(item); }} style={styles.selectBox}>
					{
						(isEidt && (item.canOperateData != "N")) ? <View style={styles.lockView}>
							{
								item.checked ? <Image style={styles.lockImage} source={correct} /> : null
							}
						</View> : null
					}
					<Text style={styles.offerTitle}>{item.goodsName}</Text>
					<Text style={[styles.textStatus, { marginRight: 5 * scale }]}>{!Utils.isEmpty(item.authStatusName) ? `(${item.authTypeName || ''} ${item.authStatusName})` : null}</Text>
					{/* {
						item.canBargainData === 'N' ? <Text style={styles.textStatus}>在其他轮成交审批中</Text> : null
					} */}
				</TouchableOpacity>
				{
					// 有applyId 代表是 成交记录 - 列表详情
					applyId ? <View style={styles.offerContent}>
						<View style={styles.offerHorizontal}>
							<View style={styles.offerContentItem}>
								<Text style={styles.offerItemTitle}>计划{salesType === 'S' ? '销售' : '采购'}量</Text>
								<Text style={styles.offerItemText}>{!Utils.isEmpty(item.maxCanSellNum) ? item.maxCanSellNum + '吨' : '-'}</Text>
							</View>
							<View style={styles.offerContentItem}>
								<Text style={styles.offerItemTitle}>客户有效提报</Text>
								<Text style={styles.offerItemText}>{!Utils.isEmpty(item.purchaseQty) ? item.purchaseQty + '吨' : '-'}</Text>
							</View>
							<View style={styles.offerContentItem}>
								<Text style={styles.offerItemTitle}>本次申请总量</Text>
								<Text style={styles.offerItemText}>{!Utils.isEmpty(item.sqPurchaseQty) ? item.sqPurchaseQty + '吨' : '-'}</Text>
							</View>
						</View>
						<View style={styles.offerHorizontal}>
							<View style={styles.offerContentItem}>
								<Text style={styles.offerItemTitle}>升贴水</Text>
								<Text style={styles.offerItemText}>{!Utils.isEmpty(item.udPrice) ? item.udPrice : '-'}</Text>
							</View>
							<View style={styles.offerContentItem}>
								<Text style={styles.offerItemTitle}>计划{salesType === 'S' ? '销售' : '采购'}价格</Text>
								<Text style={styles.offerItemText}>{!Utils.isEmpty(item.price) ? (item.price + '元/吨') : '-'}</Text>
							</View>
							<View style={styles.offerContentItem}>
								<Text style={styles.offerItemTitle}>期望{salesType === 'S' ? '销售' : '采购'}总金额</Text>
								<Text style={styles.offerItemText}>{!Utils.isEmpty(item.purchaseAmt) ? item.purchaseAmt : '-'}</Text>
							</View>
						</View>
						<View style={[styles.offerHorizontal, { marginBottom: 0 }]}>
							<View style={styles.offerContentItem}>
								<Text style={styles.offerItemTitle}>成交范围区间</Text>
								<Text style={styles.offerItemText}>{!Utils.isEmpty(item.minBaseValue) ? item.minBaseValue + '吨' : null}-{!Utils.isEmpty(item.maxBaseValue) ? item.maxBaseValue + '吨' : null}</Text>
							</View>
							<View style={styles.offerContentItem}>
								<Text style={styles.offerItemTitle}>参与企业数</Text>
								<Text style={styles.offerItemText}>{!Utils.isEmpty(item.entQty) ? item.entQty : '-'}</Text>
							</View>
							<View style={styles.offerContentItem}>
							</View>
						</View>
					</View> : <View style={styles.offerContent}>
							<View style={styles.offerHorizontal}>
								<View style={styles.offerContentItem}>
									<Text style={styles.offerItemTitle}>计划{salesType === 'S' ? '销售' : '采购'}量</Text>
									<Text style={styles.offerItemText}>{!Utils.isEmpty(item.maxCanSellNum) ? item.maxCanSellNum + '吨' : '-'}</Text>
								</View>
								<View style={styles.offerContentItem}>
									<Text style={styles.offerItemTitle}>客户有效提报</Text>
									<Text style={styles.offerItemText}>{!Utils.isEmpty(item.purchaseQty) ? item.purchaseQty + '吨' : '-'}</Text>
								</View>
								<View style={styles.offerContentItem}>
									<Text style={styles.offerItemTitle}>生效总量</Text>
									<Text style={styles.offerItemText}>{!Utils.isEmpty(item.effective) ? item.effective + '吨' : '-'}</Text>
								</View>
							</View>
							<View style={styles.offerHorizontal}>
								<View style={styles.offerContentItem}>
									<Text style={styles.offerItemTitle}>升贴水</Text>
									<Text style={styles.offerItemText}>{!Utils.isEmpty(item.udPrice) ? item.udPrice : '-'}</Text>
								</View>
								<View style={styles.offerContentItem}>
									<Text style={styles.offerItemTitle}>计划{salesType === 'S' ? '销售' : '采购'}价格</Text>
									<Text style={styles.offerItemText}>{item.bizModel == "M" || item.bizModel == "MZ" ? (item.price ? (item.price + '元/吨') : '-') : (item.offerBottomPrice ? (item.offerBottomPrice + '元/吨') : '-')}</Text>
								</View>
								<View style={styles.offerContentItem}>
									<Text style={styles.offerItemTitle}>期望{salesType === 'S' ? '销售' : '采购'}总金额</Text>
									<Text style={styles.offerItemText}>{!Utils.isEmpty(item.purchaseAmt) ? MethodUtil.toThousands(item.purchaseAmt) : '-'}</Text>
								</View>
							</View>
							<View style={[styles.offerHorizontal, { marginBottom: 0 }]}>
								<View style={styles.offerContentItem}>
									<Text style={styles.offerItemTitle}>成交范围区间</Text>
									<Text style={styles.offerItemText}>{!Utils.isEmpty(item.minBaseValue) ? item.minBaseValue + '吨' : null}-{!Utils.isEmpty(item.maxBaseValue) ? item.maxBaseValue + '吨' : null}</Text>
								</View>
								<View style={styles.offerContentItem}>
									<Text style={styles.offerItemTitle}>参与企业数</Text>
									<Text style={styles.offerItemText}>{!Utils.isEmpty(item.entQty) ? item.entQty : '-'}</Text>
								</View>
								<View style={styles.offerContentItem}>
								</View>
							</View>
						</View>
				}

			</View>
		)
	}
}

const styles = StyleSheet.create({
	offerItem: {
		backgroundColor: '#fff',
		paddingVertical: 14 * scale,
		paddingHorizontal: 8 * scale,
		borderRadius: 6 * scale,
		marginBottom: 14 * scale
	},
	offerTitle: {
		fontSize: 13 * scale,
		color: '#000000',
		fontWeight: "600"
	},
	offerContent: {
		marginTop: 7 * scale,
		backgroundColor: '#F4F7FE',
		borderRadius: 6 * scale,
		paddingVertical: 10 * scale,
	},
	offerHorizontal: {
		flexDirection: "row",
		alignItems: 'center',
		marginBottom: 25 * scale
	},
	offerContentItem: {
		flex: 1,
		alignItems: 'center',
		justifyContent: 'center',
	},
	offerItemTitle: {
		flex: 1,
		fontSize: 11 * scale,
		paddingTop: 5 * scale,
		marginBottom: 5 * scale,
	},
	offerItemText: {
		fontSize: 11 * scale,
	},
	lockImage: {
		tintColor: style.color.themeColor,
		width: 8 * scale,
		height: 8 * scale
	},
	lockView: {
		flexDirection: 'row',
		justifyContent: 'center',
		alignItems: 'center',
		height: 12 * scale,
		width: 12 * scale,
		borderWidth: 1 * scale,
		borderColor: style.color.themeColor,
		marginRight: 5 * scale,
	},
	selectBox: {
		flexDirection: 'row',
		//justifyContent: 'center',
		alignItems: 'center',
	},
	textStatus: {
		color: 'red',
		fontSize: 12 * scale,
		paddingLeft: 5 * scale
	}
})